#include "stdafx.h"
#include "Game.h"




CGame::CGame(void)
{
	m_iSpritesLoaded=0;
	
}


CGame::~CGame(void)
{
	m_iSpritesLoaded = 0;
	m_eGameState = eGameStateMenu;


}

//
//  FUNCTION: AddSprite
//
//  PURPOSE: adds a sprite into the array that contains all active sprites
//  ( a bit like addChild in Flash)
void
CGame::AddSprite(CSprite * pSprite_)
{
	m_pSprites[m_iSpritesLoaded++]=pSprite_;
}


//
//  FUNCTION: DoFrame()
//
//  PURPOSE: executes one loop of the main game loop.
//

void
CGame::DoFrame()
{
	//get input
	CInput::getInstance()->getInput(); //refresh input system


	//get dt
	float dt = CTimer::Instance()->Getdt();

	if (m_eGameState == eGameStateMenu)
	{
		//check for change of state
		if (CInput::getInstance()->getIfKeyDown(DIK_SPACE))
		{
			m_eGameState = eGameStatePlay;
		}
		//draw menu
		m_pMenuSprite->render();

	}
		
	else if (m_eGameState == eGameStatePlay)
	{
		//update

		for (int i = 0; i<m_iSpritesLoaded; i++)
		{
			m_pSprites[i]->update(dt);
		}

		//render


		for (int i = 0; i<m_iSpritesLoaded; i++)
		{
			m_pSprites[i]->render();
		}
		
	}

}